//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace Microsoft.Research.ScientificWorkflow.TridentModel
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Controls;
    using System.Windows.Media;

    using System.Workflow.ComponentModel;
    using Microsoft.Practices.EnterpriseLibrary.Logging;

    /// <summary>
    /// A model representing presentation information about particular data types
    /// </summary>
    public class DataTypeModel
    {
        #region private members
        /// <summary>
        /// Name of the data type.
        /// </summary>
        private string name;

        /// <summary>
        /// Label of the data type.
        /// </summary>
        private string label;

        /// <summary>
        /// ID of the data type.
        /// </summary>
        private string id; // ID is required in case the type isn't loaded yet

        /// <summary>
        /// Description of the data type.
        /// </summary>
        private string description;

        /// <summary>
        /// Color of the data type.
        /// </summary>
        private Color editColor = Colors.Purple;

        /// <summary>
        /// Flag to check if the datatype color is defined in the resource file.
        /// </summary>
        private bool isBuiltIn = true;

        #endregion

        #region Constructors
        /// <summary>
        /// Create a data type model given an identification string. For more about
        /// the ID string, see the comments in that property definition.
        /// </summary>
        public DataTypeModel(string id)
        {
            #region Validation of Arguments
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id");
            }
            #endregion

            // Set the id of the Data type.
            this.Id = id;
        }
        #endregion

        #region public properties
        
        /// <summary>
        /// A descriptive workflowName of the data type. This should be a short but
        /// descriptive workflowName identifying the primary use of the type.
        /// </summary>
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        /// <summary>
        /// A descriptive workflowName of the data type that is specifically shortened
        /// to fit all common uses inside a visual design tool. If the Label is
        /// not provided, the Name will be returned.
        /// </summary>
        public string Label
        {
            get
            {
                if (String.IsNullOrEmpty(label))
                    return Name;
                return label;
            }
            set { label = value; }
        }

        /// <summary>
        /// A full description of the data type.
        /// </summary>
        public string Description
        {
            get { return description; }
            set { description = value; }
        }

        /// <summary>
        /// An identification that uniquely qualifies the data type. This identification needs to
        /// be the namespaced identifier for the data type within the loaded program in order for
        /// this model to work properly. For instance, if you want to associate a data type model
        /// with an integer, the ID should be System.Int32, for a string System.String, for an
        /// XML Document System.Xml.XmlDocument, etc. In .NET terms the ID is the types Qualified
        /// Name.
        /// </summary>
        public string Id
        {
            get { return id; }
            set { id = value; }
        }

        /// <summary>
        /// The color used by the editor to give a visual clue about the data type.
        /// The colors are arbitrary, but can be helpful for usability.
        /// </summary>
        public Color PrimaryEditorColor
        {
            get
            {
                return editColor;
            }
            set
            {
                editColor = value;
            }
        }

        /// <summary>
        /// A lighter version of the PrimaryEditorColor
        /// </summary>
        public Color LightEditorColor
        {
            get
            {
                return Color.Multiply(PrimaryEditorColor, 0.8f);
            }
        }


        /// <summary>
        /// Flag to check if the datatype color is defined in the resource file.
        /// </summary>
        public bool IsBuiltIn
        {
            get { return isBuiltIn; }
            set { isBuiltIn = value; }
        }

        #endregion
    }
}
